package cn.xenosp.server.module.emailAccount.service.impl;

import cn.xenosp.server.common.tools.IdUtil;
import cn.xenosp.server.common.tools.ObjectConvert;
import cn.xenosp.server.module.emailAccount.entity.SysMailAccountVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.xenosp.server.module.emailAccount.entity.SysMailAccount;
import cn.xenosp.server.module.emailAccount.service.SysMailAccountService;
import cn.xenosp.server.module.emailAccount.mapper.SysMailAccountMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @author TongHui
* @description 针对表【sys_mail_account(邮箱账号表)】的数据库操作Service实现
* @createDate 2025-01-14 14:19:36
*/
@Service
public class SysMailAccountServiceImpl extends ServiceImpl<SysMailAccountMapper, SysMailAccount>
    implements SysMailAccountService{

    @Override
    public IPage getPage(SysMailAccountVO mailAccountVO) {
        SysMailAccount mailAccount = new SysMailAccount();
        Page page = new Page(mailAccountVO.getPage(), mailAccountVO.getLimit());
        ObjectConvert.copyVoToEntity(mailAccountVO,mailAccount);
        return baseMapper.page(page,mailAccount);
    }

    @Override
    public List<SysMailAccountVO> getAll() {
        List<SysMailAccountVO> mailAccountVOList = new ArrayList<>();
        List<SysMailAccount> all = baseMapper.getAll();
        for (SysMailAccount mailAccount : all) {
            SysMailAccountVO  mailAccountVO= new SysMailAccountVO();
            mailAccountVO.setId(mailAccount.getId());
            mailAccountVO.setMail(mailAccount.getMail());
            mailAccountVOList.add(mailAccountVO);
        }
        return mailAccountVOList;
    }

    @Override
    public void add(SysMailAccountVO mailAccountVO) {
        SysMailAccount mailAccount = new SysMailAccount();
        ObjectConvert.copyVoToEntity(mailAccountVO,mailAccount);
        mailAccount.setId(IdUtil.getId());
        save(mailAccount);
    }

    @Override
    public void save(SysMailAccountVO mailAccountVO) {
        SysMailAccount mailAccount = new SysMailAccount();
        ObjectConvert.copyVoToEntity(mailAccountVO,mailAccount);
        updateById(mailAccount);
    }

    @Override
    public void delete(String id) {
        removeById(id);
    }

    @Override
    public void delete(String[] ids) {
        removeByIds(Arrays.asList(ids));
    }
}




